﻿@model AffiliatedOrderListModel
@{
    var defaultGridPageSize = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().DefaultGridPageSize;
    var gridPageSizes = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().GridPageSizes;

}
<table width="100%">
    <tr>
        <td class="adminTitle">
            @Html.NopLabelFor(model => model.StartDate):
        </td>
        <td class="adminData">
            @Html.EditorFor(model => model.StartDate)
        </td>
    </tr>
    <tr>
        <td class="adminTitle">
            @Html.NopLabelFor(model => model.EndDate):
        </td>
        <td class="adminData">
            @Html.EditorFor(model => model.EndDate)
        </td>
    </tr>
    <tr>
        <td class="adminTitle">
            @Html.NopLabelFor(model => model.OrderStatusId):
        </td>
        <td class="adminData">
            @Html.DropDownList("OrderStatusId", Model.AvailableOrderStatuses)
        </td>
    </tr>
    <tr>
        <td class="adminTitle">
            @Html.NopLabelFor(model => model.PaymentStatusId):
        </td>
        <td class="adminData">
            @Html.DropDownList("PaymentStatusId", Model.AvailablePaymentStatuses)
        </td>
    </tr>
    <tr>
        <td class="adminTitle">
            @Html.NopLabelFor(model => model.ShippingStatusId):
        </td>
        <td class="adminData">
            @Html.DropDownList("ShippingStatusId", Model.AvailableShippingStatuses)
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <input type="button" id="search-orders" class="k-button" value="@T("Admin.Common.Search")" />
        </td>
    </tr>
</table>

<div id="orders-grid"></div>

<script>
    $(document).ready(function () {
        $("#orders-grid").kendoGrid({
            dataSource: {
                type: "json",
                transport: {
                    read: {
                        url: "@Html.Raw(Url.Action("AffiliatedOrderList", "Affiliate"))",
                        type: "POST",
                        dataType: "json",
                        data: additionalData
                    }
                },
                schema: {
                    data: "Data",
                    total: "Total",
                    errors: "Errors"
                },
                error: function(e) {
                    display_kendoui_grid_error(e);
                    // Cancel the changes
                    this.cancelChanges();
                },
                pageSize: @(defaultGridPageSize),
                serverPaging: true,
                serverFiltering: true,
                serverSorting: true
            },
            pageable: {
                refresh: true,
                pageSizes: [@(gridPageSizes)]
            },
            editable: {
                confirmation: false,
                mode: "inline"
            },
            scrollable: false,
            columns: [{
                field: "Id",
                title: "@T("Admin.Affiliates.Orders.Order")",
                width: 50
            }, {
                field: "OrderStatus",
                title: "@T("Admin.Affiliates.Orders.OrderStatus")"
            }, {
                field: "PaymentStatus",
                title: "@T("Admin.Affiliates.Orders.PaymentStatus")"
            },{
                field: "ShippingStatus",
                title: "@T("Admin.Affiliates.Orders.ShippingStatus")"
            },{
                field: "OrderTotal",
                title: "@T("Admin.Affiliates.Orders.OrderTotal")"
            },{
                field: "CreatedOn",
                title: "@T("Admin.Affiliates.Orders.CreatedOn")",
                type: "date",
                format: "{0:G}"
            },{
                field: "Id",
                title: "@T("Admin.Common.View")",
                width: 100,
                template: '<a href="@Url.Content("~/Admin/Order/Edit/")#=Id#">@T("Admin.Common.View")</a>'
            }]
        });
    });
</script>

<script type="text/javascript">

    var selectedIds = [];
    var reportAggregates = "";

    $(document).ready(function () {

        //search button
        $('#search-orders').click(function () {
            //search
            var grid = $('#orders-grid').data('kendoGrid');
            grid.dataSource.page(1); //new search. Set page size to 1
            //grid.dataSource.read(); we already loaded the grid above using "page" function
            return false;
        });
    });

    function additionalData() {
        var data = {
            AffliateId: @(Model.AffliateId),
            StartDate: $('#@Html.FieldIdFor(model => model.StartDate)').val(),
            EndDate: $('#@Html.FieldIdFor(model => model.EndDate)').val(),
            OrderStatusId: $('#@Html.FieldIdFor(model => model.OrderStatusId)').val(),
            PaymentStatusId: $('#@Html.FieldIdFor(model => model.PaymentStatusId)').val(),
            ShippingStatusId: $('#@Html.FieldIdFor(model => model.ShippingStatusId)').val()
        };
        addAntiForgeryToken(data);
        return data;
    }
</script>